//
//  BuyGoodsView.m
//  Youhuiju
//
//  Created by 余尚飞 on 16/8/2.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "BuyGoodsView.h"

@interface BuyGoodsView ()

@property(nonatomic,strong)UIButton * addCartBtn;
@property(nonatomic,strong)UIButton * buyBtn;
@property(nonatomic,strong)UILabel * collectLabel;
@property(nonatomic,strong)UILabel * addCartLabel;
@property(nonatomic,strong)UIView *line;
@end

@implementation BuyGoodsView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self creatView];
    }
    return self;
}

-(void)creatView
{
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = [UIColor colorWithHexString:@"eeeeee"];
    [self addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top);
        make.height.mas_offset(1 * FitH);
    }];
    
    
    self.buyBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.buyBtn.tag = 0;
    [self.buyBtn setTitle:@"立即购买" forState:UIControlStateNormal];
    
    self.buyBtn.tintColor = [UIColor whiteColor];
    self.buyBtn.backgroundColor = [UIColor colorWithHexString:@"fd743e"];
    [self.buyBtn addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.buyBtn];
    [self.buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.mas_top).offset(8 * FitH);
//        make.left.equalTo(self.mas_left).offset(261 * FitW);
        make.centerY.equalTo(self.mas_centerY);
        make.centerX.equalTo(self.mas_centerX);
        make.size.mas_offset(CGSizeMake(114 * FitW, 41 * FitH));
    }];
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];  // 设置渐变效果
    gradientLayer.bounds = self.bounds;
    gradientLayer.borderWidth = 0;
    
    gradientLayer.frame = CGRectMake(0, 0, 114 * FitW, 41 * FitH);
    gradientLayer.colors = [NSArray arrayWithObjects:
                            (id)[[UIColor colorWithHexString:@"ff9865"] CGColor],
                            (id)[[UIColor colorWithHexString:@"fc4d7e"] CGColor], nil ];
    
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.cornerRadius = 3 * FitH;
    
    [self.buyBtn.layer insertSublayer:gradientLayer atIndex:0];
    self.buyBtn.layer.cornerRadius = 3 * FitH;
    
    
    self.collectBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.collectBtn.tag = 2;
    [self.collectBtn setBackgroundImage:LoadImage(@"collectkong") forState:UIControlStateNormal];
[self.collectBtn addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside];    [self addSubview:self.collectBtn];
    [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.buyBtn.mas_left).offset(-57 * FitW);
        make.top.equalTo(self.buyBtn.mas_top).offset(5 * FitH);
        make.size.mas_offset(CGSizeMake(22 * FitW, 22 * FitH));
    }];
    
    
    
    
    self.collectLabel = [[UILabel alloc]init];
    self.collectLabel.text = @"收藏";
    self.collectLabel.textColor = [UIColor colorWithHexString:@"999999"];
    self.collectLabel.font = [UIFont systemFontOfSize:10 * FitH];
    [self addSubview:self.collectLabel];
    [self.collectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collectBtn.mas_bottom).offset(5 * FitH);
        make.centerX.equalTo(self.collectBtn.mas_centerX);
        make.height.mas_offset(10 * FitH);
    }];
    
    
    self.addCartBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.addCartBtn.tag = 1;
    [self.addCartBtn setBackgroundImage:LoadImage(@"goodsaddcart") forState:UIControlStateNormal];
    [self.addCartBtn addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.addCartBtn];
    [self.addCartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buyBtn.mas_right).offset(57 * FitW);
        make.top.equalTo(self.buyBtn.mas_top).offset(5 * FitH);
        make.size.mas_offset(CGSizeMake(22 * FitW, 22 * FitH));
    }];
    
    self.addCartLabel = [[UILabel alloc]init];
    self.addCartLabel.text = @"加入购物车";
    self.addCartLabel.textColor = [UIColor colorWithHexString:@"999999"];
    self.addCartLabel.font = [UIFont systemFontOfSize:10 * FitH];
    [self addSubview:self.addCartLabel];
    [self.addCartLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.addCartBtn.mas_bottom).offset(5 * FitH);
        make.centerX.equalTo(self.addCartBtn.mas_centerX);
        make.height.mas_offset(10 * FitH);
    }];
    
}

-(void)buttonClickedAction:(UIButton *)sender
{
    if (self.buttonClickedHandler)
    {
        self.buttonClickedHandler(sender.tag);
    }
}

@end
